<template>
    <div class="file">
        <el-card>
            <el-row style="padding: 15px 10px">
                <el-col :span="4">
                    <el-input v-model="search.clauses[0].value" placeholder="根据文件id查找" @change="getList"></el-input>
                </el-col>
                <el-col :span="4" style="margin-left: 20px">
                    <el-input v-model="search.clauses[1].value" placeholder="根据原始文件名查找" @change="getList"></el-input>
                </el-col>

            </el-row>
            <el-table
                    ref="singleTable"
                    :data="tableData"
                    border
                    :header-cell-style="tableHeader"
                    highlight-current-row
                    style="width: 100%;font-size: 16px">
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        property="fileId"
                        label="文件id"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        property="filePath"
                        label="文件地址"
                        min-width="120">
                </el-table-column>
                <el-table-column label="详情" align="center">
                    <template slot-scope="scope">
                        <img :src="scope.row.filePath" style="width: 60px;height: 50px">
                    </template>
                </el-table-column>
                <el-table-column
                        property="originalFileName"
                        label="原始文件名">
                </el-table-column>
                <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.row.fileId)">删除</el-button>
                </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="search.pageNum"
                    :page-sizes="[10,20,30, 40, 50]"
                    :page-size="search.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-card>
        <el-dialog
                title="修改文件原始名"
                :visible.sync="dialogVisible"
                width="30%"
                :before-close="handleClose">
            <el-form label-width="20%" :model="fileData" :rules="fileData" :ref="fileData">

                <el-form-item label="原始文件名" style="padding: 0 10px"  prop="userName">
                    <el-input v-model="fileData.originalFileName"></el-input>
                </el-form-item>
                <el-form-item label-width="60%">
                    <el-button  size="small" @click="dialogVisible = false">取 消</el-button>
                    <el-button size="small" type="primary" @click="submit(fileData)">确 定</el-button>
                </el-form-item>
            </el-form>

        </el-dialog>
    </div>
</template>

<script>
    import Message from '../../../components/messages/index'
    export default {
        name: "FileManage",
        data(){
            return{
                tableHeader:{
                    "background-color":"#7fa1be99",
                    "color":"white",
                    "font-size":"18px"
                },
                tableData: [],
                total: 0,
                search:{
                    pageSize:10,
                    pageNum:1,
                    clauses:[
                        {
                           column:"fileId",
                           operation:"like",
                           value:""
                        },{
                            column:"originalFileName",
                            operation:"like",
                            value:""
                        }
                    ],
                    sortMap:{}
                },
                fileData:{},
                dialogVisible:false

            }
        },
        methods:{
            handleClose(){
                this.fileData = {};
                this.dialogVisible = false;
            },
            handleSizeChange(val){
                this.search.pageSize = val;
                this.getList();
            },
            handleEdit(data){
                this.fileData = data;
                this.dialogVisible = true;
            },
            submit(data){
                this.$http.post("/uploadFile/update",data).then(res=>{
                    if (res.status===200){
                        Message.success("修改成功");
                        this.dialogVisible = false;
                    }
                })
            },
            handleDelete(data){
                Message.confirm("是否需要删除？").then(()=>{
                    this.$http.get("/uploadFile/delete/"+data).then(res=>{
                        if (res.status===200){
                            Message.success("删除成功");
                            this.getList();
                        }
                    })
                })
            },
            handleCurrentChange(val){
                this.search.pageNum = val;
                this.getList();
            },
            getList(){
                this.$http.post("/uploadFile/page",this.search).then(response=>{
                    if (response.status===200){
                        this.tableData = response.data.list;
                        this.total=response.data.total;
                    }
                })
            }
        },
        mounted(){
            this.getList();
        }
    }
</script>

<style scoped lang="less">
    .file{
        width: 100%;
        height: calc(~'100vh - 65px');
    }

</style>